<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <title>博客详情</title>
</head>
<body>
<!--导航条-->
<nav th:replace="_fragments :: menu(0)"></nav>
<!--中间内容-->
<div id="waypoint"  class="m-container m-padded-tb-big animated bounceInUp">
    <div class="ui container">
        <!--   中间内容     -->
        <div class="ui top attached m-bg segment">
            <div class="ui  horizontal link list">
                <div class="item">
                    <img th:src="@{${blog.user.avater}}" alt="" class="ui avatar image site-author-image">
                    <div class="content"><a href="#" style="color: #ffa2a2!important;" class="m-pink m-font-big" th:text="${blog.user.nickname}">管理员</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon m-pink"></i><span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2021-01-17</span>
                </div>
                <div class="item">
                    <span th:text="${blog.views}">53</span><span class="m-pink"> ℃</span>
                </div>
            </div>
        </div>
        <!--   图片区域     -->
        <div class="ui attached m-bg segment">
            <!--  fulid作用是撑满segment的整个空间 -->
            <img id="blogFirstPicture" th:src="@{${blog.firstPicture}}" alt="" class="ui fluid rounded image ">
        </div>
        <!--   内容区域     -->
        <div class="ui attached padded m-bg segment">
            <div class="ui right aligned basic m-bg segment">
                <div class="ui m-bg m-pink-label basic label" th:text="${blog.flag}">原创</div>
            </div>
            <h1 class="ui header center aligned" th:text="${blog.title}">RabbitMQ</h1>
            <div id="content" class="typo typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${blog.content}">

            </div>
            <!--    标签   -->
            <div class="m-padded-lr m-bg">
                <div class="cloud m-bg">
                    <ul>
                        <li>
                            <a href="#" th:each="tag : ${blog.tags}" th:text="${tag.name}">基础知识</a>
                        </li>
                    </ul>
                </div>
            </div>
            <!--    赞赏       -->
            <div class="ui center aligned basic m-bg segment">
                <button id="payButton" class="ui orange basic circular button">赞赏</button>
                <div class="ui payMe flowing popup m-bg bottom center transition " style="inset: 50px auto auto 354.594px;">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <p style="color: red;font-size: small;text-align:center" class="h6 small">感谢请我吃糖~</p>
                            <div class="image">
                                <img th:src="@{/img/wxpay.PNG}" alt="" class="ui rounded bordered image" style="width: 120px">
                                <div>微信</div>
                            </div>
                            <div class="image">
                                <img th:src="@{/img/zfb.PNG}" alt="" class="ui rounded bordered image" style="width: 120px">
                                <div>支付宝</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--   博客信息     -->
        <div class="ui message error attached  segment m-opacity-mini mini">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span th:text="${blog.user.nickname}">管理员</span><a class="m-pink" href="/about" target="_blank">（联系作者）</a></li>
                        <li>发表时间：<span th:text="${blog.createTime}">2021-01-12 16:04</span>
                        </li>
                        <li>版权声明：自由转载-非商用-非衍生-保持署名</li>
                        <li>公众号转载：请在文末添加作者公众号二维码</li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img th:src="@{/img/wechat.jpg}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                </div>
            </div>
        </div>
        <!--   留言区域     -->
        <div class="ui attached bottom segment m-bg">
            <!--留言区域列表-->
            <div id="comment-container" class="ui segment m-bg m-top-color">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%;">
                        <h3 class="ui dividing header">评论</h3>
                        <!--多个评论-->
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img class="site-author-image" th:src="@{${comment.avatar}}">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Abalone</span>
                                    <span th:class="${comment.adminComment} ? 'ui mini  left pointing m-white m-bg-pink label m-padded-mini':'ui mini  left pointing  label m-padded-mini'"  th:text="${comment.adminComment} ? '站长':'游客'">游客</span>
                                </a>
                                <div class="metadata">
                                    <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">2021-01-17 12:01</span>
                                </div>
                                <div class="text" th:utext="${comment.content}">妙啊,简洁易懂:)</div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Abalone" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)>0}">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img class="site-author-image" th:src="@{${reply.avatar}}">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">和煦</span>
                                            &nbsp;<span class="m-pink" th:text="'@ '+${reply.parentComment.nickname}">@ 随心</span>
                                        </a>
                                        <span th:class="${reply.adminComment} ? 'ui mini  left pointing m-white m-bg-pink label m-padded-mini':'ui mini  left pointing  label m-padded-mini'" th:text="${reply.adminComment} ? '站长':'游客'">游客</span>
                                        <div class="metadata">
                                            <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">2021-02-03 17:13</span>
                                        </div>
                                        <div class="text" th:utext="${reply.content}">sdasasdsa</div>
                                        <div class="actions">
                                            <a class="reply" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--输入区域-->
            <div id="comment-form" class="ui  form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="ui animated rotatelnDownLeft error mini message"></div>
                <div class="fields">
<!--                    <input id="inputId" type="hidden" name="blogId" value="1610438635521">-->
<!--                    <input type="hidden" name="parentCommentId" value="-1">-->
                    <!--表情按钮-->
                    <div class="field  m-margin-bottom-small m-mobile-wide" data-tooltip="表情未加载完全或点击无响应可刷新页面重试">
                        <button id="emojiBtn" type="button" class="ui yellow button m-mobile-wide"><i class="large smile outline icon"></i>表情
                        </button>
                    </div>
                    <div class="field m-margin-bottom-small m-mobile-wide">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" class="m-bg" name="nickname" th:value="${session.user}!=null ? ${session.user.nickname}"  placeholder="您的昵称" value="">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" class="m-bg" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field m-margin-bottom-small m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui secondary m-bg-pink button m-mobile-wide">
                            <i class="edit icon"></i>
                            发布
                        </button>
                    </div>
                </div>
                <div class="field">
                    <div id="commentEditor" class="fields" contenteditable="true" data-placeholder="邮件地址不会被公开，只会作为回复提醒的联系方式；如果需要回复提醒功能，请输入正确的邮箱..."></div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--工具条-->
<div id="toolbar" class="m-bg animated fadeIn m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons">
        <button type="button" class="ui toc secondary m-bg-pink button">目录</button>
        <a href="#comment-container" class="ui  secondary m-bg-pink button">留言</a>
        <button type="button" class="ui share secondary m-bg-pink button visible">分享</button>
        <button class="ui wechat icon secondary m-bg-pink button"><i class="big qrcode icon"></i></button>
        <div id="toTop-button" class="ui secondary m-bg-pink icon button"><i class="chevron up icon"></i></div>
    </div>
</div>
<!--生成的目录所包含的div-->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px;">
    <ol class="js-toc"></ol>
</div>
<!--生成的二维码-->
<div id="qrcode" class="ui wechat-qr flowing popup left center transition hidden" style="inset: 43.844px 55.0312px auto auto; width: 130px !important;" title="http://47.94.235.49/blog/1610726565911">
    <p style="color: red;font-size: small;text-align:center" class="h6 small">手机扫码阅读本文</p>
</div>

<div class="ui share-container flowing popup  transition hidden" style="inset: 44.3438px 55.0312px auto auto; width: 240px !important; display: block !important;">
    <div class="ui bottom attached segment">
        <button title="点击分享微博" onclick="sinaWeiBo()" class="ui weibo circular icon button"><i class="red weibo icon"></i></button>
        <button title="点击分享微信" onclick="shareWeiXin()" class="ui wechat circular icon button"><i class="green weixin icon"></i></button>
        <button title="点击分享QQ好友" onclick="shareQQ()" class="ui qq circular icon button"><i class="blue qq icon"></i></button>
        <button title="点击分享QQ空间" onclick="shareQQZone()" class="ui qqZone circular icon button"><i class="yellow share icon"></i></button>
    </div>
</div>
<input type="hidden" id="blogTitle" value="Thymeleaf">
<input type="hidden" id="firstPicture" value="http://cdn.sakurac.cn/blog25.jpg">
<input type="hidden" id="blogId" th:value="'/blog/'+${blog.id}">
<input type="hidden" id="loadId" th:value="'/comments/'+${blog.id}">
<!--页脚-->
<footer th:replace="_fragments::footer"></footer>
<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<!--/*/</th:block>/*/-->
<!--适配移动端和电脑端-->
<!--樱花飘落-->
<script type="text/javascript">
    var browser = {
        versions: function () {
            var u = navigator.userAgent, app = navigator.appVersion;
            return {     //移动终端浏览器版本信息
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应用程序，没有头部与底部
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
    if (browser.versions.mobile) {
        //执行移动端的相关代码
        //alert("移动端");
        //设置移动端不显示网易云音乐插件
        /*      onload = function () {
                  var MusicDivShow = document.getElementById('netEasy-music');//获取指定div中的元素
                  MusicDivShow.style.display = 'none';//控制层隐藏
              };*/
    } else if (!browser.versions.mobile) { //非移动端，动态加载js和div
        //设置电脑端显示网易云音乐插件
        // onload = function () {
        //     var MusicDivShow = document.getElementById('netEasy-music');//获取指定div中的元素
        //     MusicDivShow.style.display = 'block';//控制层显示
        // };
        // var script1 = document.createElement('script');
        // script1.type = 'text/javascript';
        // script1.src = '\\js\\snow.js';

        // <!-- 天气预报 -->
        // WIDGET = {FID: 'EtgqPWMbdv'}
        // var script4 = document.createElement('script');
        // script4.type = 'text/javascript';
        // script4.src = 'https://apip.weatherdt.com/float/static/js/r.js?v=1111';

        var script2 = document.createElement('script');
        script2.type = 'text/javascript';
        // script2.src = 'https://cdn.jsdelivr.net/gh/yremp/yremp-js@1.5/sakura.js';
        script2.src = 'https://yremp.live/wp-content/uploads/resource/js/sakura.js';

        //画图
        // var script3 = document.createElement('script');
        // script3.type = 'text/javascript';
        // script3.color = '220,220,220';
        // script3.opacity = '0.7';//透明度
        // script3.zIndex = '-2';
        // script3.count = '200';
        // script3.src = '//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js';

        // $('body').append(script1);
        // $('body').append(script4);天气预报
        $('body').append(script2);
        // $('body').append(script3);划线背景
    }
</script>
<script th:inline="javascript">
    <!--  滚动侦测  -->
    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function(direction) {
            if(direction == 'down'){
                $("#toolbar").show(500);
            }else {
                $("#toolbar").hide(500);
            }
        }
    })
    <!-- 回到顶部   -->
    $("#toTop-button").click(function (){
        $(window).scrollTo(0,500)
    });
    <!-- 二维码生成   -->
    var url = $("#blogId").val();
    console.log(url);
    var serurl = "http://www.wuhobin.top"
    var qrcode = new QRCode("qrcode", {
        text: serurl+url,
        width: 120,
        height: 120,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });
    /*目录初始化*/
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });

    <!-- 移动端导航条   -->
    $(".toggle.menu").click(function (){
        $(".m-item").toggleClass("m-mobile-hide")
    })
    /*赞赏弹窗*/
    $('#payButton').popup({
        popup: $('.payMe.popup'),
        on: 'hover',
        position: 'bottom center'
    });
    // 目录生成
    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });
    //  微信二维码
    $('.wechat').popup({
        popup: $('.wechat-qr'),
        position: 'left center'
    });
    /*加载emoji表情*/
    onload = function () {
        $("#commentEditor").emoji({
            button: "#emojiBtn",  //评论表情
            showTab: false,
            animation: 'slide',
            basePath: '/img/emoji',
            icons: emojiLists
        });

        $("#commentText").emojiParse({
            basePath: '/img/emoji',
            icons: emojiLists
        });
    };

    //评论表单验证
    $('.ui.form').form({
        fields: {
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });$(function () {
        //确认
        $('#btn_ok1').click(function () {
            $('#window1').attr('hidden', 'hidden');
        });
        $('#btn_ok2').click(function () {
            $('#window2').attr('hidden', 'hidden');
        });
    });
    $('.ui.checkbox').checkbox();
    /*监听指定元素的class属性*/
    $(document).ready(function () {
        var targetNode = document.getElementById('open-mail');//获取监听元素
        var config = {attributes: true};
        var callback = function (mutationsList) {
            for (var mutation of mutationsList) {
                if (mutation.type == 'attributes') {
                    if ($(targetNode).hasClass("checked")) {//当class属性改变时触发事件
                        $('#window2').removeAttr('hidden');
                    }
                }
            }
        };
        var observer = new MutationObserver(callback);
        observer.observe(targetNode, config);
    });

    $(function () {
        var loadUrl = $("#loadId").val();
        $("#comment-container").load(loadUrl);
    })

    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        var text = document.getElementById("commentEditor").innerHTML;
        if (boo && text != "") {
            console.log('校验成功');
            postData();
        } else if (text == "") {
            console.log('留言数据校验不通过');
            $('#window1').removeAttr('hidden');
            return;
        }
    });
    function postData() {
        var url = '/comments';
        console.log(url);
        $("#comment-container").load(url, {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": document.getElementById("commentEditor").innerHTML,
        }, function (responseTxt, statusTxt, xhr) {
            //$(window).scrollTo($('#comment-container'),500);
            console.log('推出postData');
            clearContent();
        });
    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("#commentEditor").attr("data-placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }

    function clearContent() {
        $("[name='parentComment.id']").val(-1);
        document.getElementById("commentEditor").innerText = '';
        $("#commentEditor").attr("data-placeholder", "邮件地址不会被公开，只会作为回复提醒的联系方式；如果需要回复提醒功能，请输入正确的邮箱...");
    }

    /*分享*/
    $('.share.button').popup({
        popup: $('.share-container.popup'),
        on: 'click',
        position: 'left center'
    });
    localStorage.setItem("blogFirstPicture", document.getElementById("blogFirstPicture").value);
    localStorage.setItem("blogTitle", document.getElementById("blogFirstPicture").value + '-Sakura°博客');

    /*QQ分享*/
    function shareQQ() {
        var param = {
            url: 'http://sakurac.cn/blog/' + localStorage.getItem("blogId"),
            desc: '发现了一篇不错的博客，一起来看看吧~',
            title: localStorage.getItem("blogTitle") + " from Sakura°博客",
            summary: '这篇博客内容不错，一起来看看吧！',
            pics: localStorage.getItem("blogFirstPicture"),
            //flash : '',
            sharesource: 'qq',
            site: 'Sakura°_Blog'
        };
        var s = [];
        for (var i in param) {
            s.push(i + '=' + encodeURIComponent(param[i] || ''));
        }
        var targetUrl = "https://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&');
        // var targetUrl = "http://connect.qq.com/widget/shareqq/index.html?" + s.join('&') ;
        //window.location.href=targetUrl;
        window.open(targetUrl, 'qq', 'height=800, width=800');
    }

    /*分享QQ空间*/
    function shareQQZone() {
        var param = {
            url: window.location.href,
            sharesource: 'qzone',
            title: localStorage.getItem("blogTitle") + " from Sakura°博客",
            summary: '这篇博客内容不错，一起来看看吧！',
            pics: localStorage.getItem("blogFirstPicture"),
        };
        var s = [];
        for (var i in param) {
            s.push(i + '=' + encodeURIComponent(param[i] || ''));
        }
        var targetUrl = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?" + s.join('&');
        //window.location.href=targetUrl;
        window.open(targetUrl, 'qqZone', 'height=800, width=800');
    }

    /**
     * 微信分享
     * @return {[type]} [description]
     */
    function shareWeiXin() {
        var url = window.location.href,
            encodePath = encodeURIComponent(url),
            targetUrl = 'http://qr.liantu.com/api.php?text=' + encodePath;
        window.open(targetUrl, 'weixin', 'height=400, width=400');
    }

    /**
     * 分享新浪微博
     * @param  {[type]} title [分享标题]
     * @param  {[type]} url   [分享url链接，默认当前页面]
     * @param  {[type]} pic   [分享图片]
     * @return {[type]}       [description]
     */
    function sinaWeiBo() {
        var param = {
            url: window.location.href,
            type: '3',
            count: '1', /** 是否显示分享数，1显示(可选)*/
            appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
            title: localStorage.getItem("blogTitle") + " from Sakura°博客", /** 分享的文字内容(可选，默认为所在页面的title)*/
            pic: localStorage.getItem("blogFirstPicture"), /**分享图片的路径(可选)*/
            ralateUid: '', /**关联用户的UID，分享微博会@该用户(可选)*/
            rnd: new Date().valueOf()
        }
        var temp = [];
        for (var p in param) {
            temp.push(p + '=' + encodeURIComponent(param[p] || ''))
        }
        var targetUrl = 'http://service.weibo.com/share/share.php?' + temp.join('&');
        //window.open(targetUrl, 'sinaweibo', 'height=430, width=400');
        window.location.href = targetUrl;
    }

</script>
</body>
</html>
